function relax3

%  this finds 0.5*T

global lam

clf

T=1.5-log(2);
x0=-2.3381074104597670385;
   
N=12;
ex=linspace(1,5,N);
ratio=zeros(N,1);
for il=1:N
    lam=10^ex(il);
    ep(il)=1/lam;

    %  initial values
    if il==1
        tmax=T-x0*ep(il)^(4/3)*1.5;
    else
        tmax=t(it+2);
    end
    y10=2; y20=-2/3;
    y0=[y10 y20];
    % calculate solution using a MATLAB routine
    options = odeset('RelTol', 1e-12,'AbsTol',1e-12);
    [t,y] = ode23s(@rhs,[0 tmax],y0,options);
    %[t,y] = ode45(@rhs,[0 tmax],y0,options);
    %[t,y] = ode78(@rhs,[0 tmax],y0,options);

    for it=3:length(t)-2
        if y(it,1)<y(it-2,1) && y(it,1)<y(it+2,1)
            break
        end
    end

    if it<length(t)-1
        ratio(il)=(t(it)-T)/(ep(il)^(4/3));
    else
        il
        lam
        tmax
        t(length(t))
        return
    end

end

ep
ratio

semilogx(1./ep,ratio,'b','LineWidth',1.5)
hold on
semilogx([1 10^5],[-x0 -x0],'k','LineWidth',1)
xlabel('lambda','FontWeight','bold')
ylabel('ratio','FontWeight','bold')
grid on

box on
set(gca,'FontSize',12,'FontWeight','bold')

hold off

%  define f(t,y)
function dy=rhs(t,y)
global lam
dy=zeros(2,1);
dy(1) = lam^2*(y(1)*(1-y(1)^2/3)-y(2));
dy(2) = y(1);








